﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace JuCloudy.Sys.App.ErrorManagement
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void OnLoad()
        {
            this._dg.SelectionChanged += (obj, e) =>
            {
                if (e.AddedItems != null || e.AddedItems.Count > 0)
                {
                    this._ViewBrowserInfoBtn.IsEnabled = true;
                    this._ViewDetailBtn.IsEnabled = true;
                    this._ViewUserAgent.IsEnabled = true;
                }
                else
                {
                    this._ViewBrowserInfoBtn.IsEnabled = false;
                    this._ViewDetailBtn.IsEnabled = false;
                    this._ViewUserAgent.IsEnabled = false;
                }
            };
        }

        public ObservableCollection<JuCloudy.Data.Entity.SysErrorLog> Entities
        {
            get { return (ObservableCollection<JuCloudy.Data.Entity.SysErrorLog>)this._dg.ItemsSource; }
            set { this._dg.ItemsSource = value; }
        }

        public void InitData()
        {
            SystemErrorLog.SystemErrorLogSoapClient client
                = new SystemErrorLog.SystemErrorLogSoapClient();

            client.GetEntitiesCompleted += (obj, e) =>
            {
                if (e.Error != null)
                    throw e.Error;
                else
                {
                    this.Entities = (ObservableCollection<JuCloudy.Data.Entity.SysErrorLog>)e.Result.Deserialize(typeof(ObservableCollection<JuCloudy.Data.Entity.SysErrorLog>));
                }
            };
        }
    }
}
